package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCmsSc;
import com.ruoyi.system.service.ISysCmsScService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 古诗词Controller
 * 
 * @author ruoyi
 * @date 2021-01-31
 */
@Controller
@RequestMapping("/system/sc")
public class SysCmsScController extends BaseController
{
    private String prefix = "system/sc";

    @Autowired
    private ISysCmsScService sysCmsScService;

    @RequiresPermissions("system:sc:view")
    @GetMapping()
    public String sc()
    {
        return prefix + "/sc";
    }

    /**
     * 查询古诗词列表
     */
    @RequiresPermissions("system:sc:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCmsSc sysCmsSc)
    {
        startPage();
        List<SysCmsSc> list = sysCmsScService.selectSysCmsScList(sysCmsSc);
        return getDataTable(list);
    }

    /**
     * 导出古诗词列表
     */
    @RequiresPermissions("system:sc:export")
    @Log(title = "古诗词", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysCmsSc sysCmsSc)
    {
        List<SysCmsSc> list = sysCmsScService.selectSysCmsScList(sysCmsSc);
        ExcelUtil<SysCmsSc> util = new ExcelUtil<SysCmsSc>(SysCmsSc.class);
        return util.exportExcel(list, "sc");
    }

    /**
     * 新增古诗词
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存古诗词
     */
    @RequiresPermissions("system:sc:add")
    @Log(title = "古诗词", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysCmsSc sysCmsSc)
    {
        return toAjax(sysCmsScService.insertSysCmsSc(sysCmsSc));
    }

    /**
     * 修改古诗词
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SysCmsSc sysCmsSc = sysCmsScService.selectSysCmsScById(id);
        mmap.put("sysCmsSc", sysCmsSc);
        return prefix + "/edit";
    }

    /**
     * 修改保存古诗词
     */
    @RequiresPermissions("system:sc:edit")
    @Log(title = "古诗词", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysCmsSc sysCmsSc)
    {
        return toAjax(sysCmsScService.updateSysCmsSc(sysCmsSc));
    }

    /**
     * 删除古诗词
     */
    @RequiresPermissions("system:sc:remove")
    @Log(title = "古诗词", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysCmsScService.deleteSysCmsScByIds(ids));
    }
}
